package com.softeem.ossmusic.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.softeem.ossmusic.comm.R;
import com.softeem.ossmusic.entity.Album;
import com.softeem.ossmusic.entity.Music;
import com.softeem.ossmusic.mapper.AlbumMapper;
import com.softeem.ossmusic.service.MusicService;
import com.softeem.ossmusic.mapper.MusicMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
import org.springframework.stereotype.Service;

/**
* @author softeem
* @description 针对表【music】的数据库操作Service实现
* @createDate 2025-10-28 11:42:45
*/
@Service
public class MusicServiceImpl extends ServiceImpl<MusicMapper, Music>
    implements MusicService{

    @Autowired
    private AlbumMapper albumMapper;

    @Override
    public R musicDetails(Integer id) {
        //根据id查询音乐
        Music m = getById(id);
        if(m == null){
            return R.error().setMsg("音乐不存在");
        }
        if(m.getAid() == null){
            return R.error().setMsg("专辑不存在");
        }
        //根据音乐的所属专辑id查询专辑信息
        Album a = albumMapper.selectById(m.getAid());
        //将当前专辑设置给音乐对象
        m.setAlbum(a);
        //返回结果
        return R.success().setData(m);
    }
}




